Passwordless ssh

last modified

2024–9–27

On the local machine, create private and public keys:

ssh-keygen

The keys are stored in ~/.ssh as id_rsa and id_rsa.pub. You can choose whether to protect the private key by a passphrase (see below).

Copy the public key onto the remote machine for which you want passwordless ssh:

ssh-copy-id -p <port> <user>@<machine>

On the remote machine, the public keys is added to ~/.ssh/authorized_keys.

You can now login without password – the private key is used instead.

ssh -p <port> <user>@<machine>

However, if you chose to protect the private key by a passphrase, it has to provided upon each login to access the key. To avoid that, run once before:

ssh-add

This prompts for the passphrase and obtains and remembers the private key for further logins.